<?php

namespace App\Http\Validate\Article;

use App\Error\BaseError;
use App\Exceptions\KfHttpResponseException;
use App\Http\Validate\AbstractBaseValidate;
use App\Models\Article\ArticleCategoryModel;
use App\Models\Article\ArticleModel;
use App\Models\Article\ArticleRecommendModel;
use App\Models\Article\ArticleUserRelationModel;
use App\Models\Article\Category\ArticleCategoryOperateResultModel;
use App\Models\BaseModel;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class CategoryValidate extends AbstractBaseValidate
{
    function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [];
    }

    function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [

        ];
    }

    function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.

    }

    function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [
        ];
    }

    /**
     * 操作校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function operateValidate(array $params)
    {
        return self::getInstance()->validate(
            ["targetId", "operateType", "status"],
            $params,
            [
                "targetId"    => [
                    "required",
                    "int",
                    Rule::exists((new ArticleCategoryModel())->getTable(), "id")
                        ->where("isDeleted", BaseModel::DELETE_NO)
                ],
                "operateType" => self::intInValidateBuild(true, ArticleCategoryOperateResultModel::OPERATE_TYPE_TEXT),
                "status"      => self::intInValidateBuild(true, ArticleCategoryOperateResultModel::STATUS_TEXT)
            ]
        );
    }

    /**
     * 操作列表校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function operateListValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                "pageSize",
                "pageNum",
                "type",
                "name"
            ],
            $params,
            [
                "pageSize" => "required|int|min:1|max:100",
                "pageNum"  => "required|int|min:1",
                "type"     => [
                    "required",
                    "int",
                    Rule::in([
                        ArticleCategoryOperateResultModel::OPERATE_TYPE_COLLECT,
                        ArticleCategoryOperateResultModel::OPERATE_TYPE_SUPPORT
                    ])
                ],
                "name"     => "sometimes|string"
            ]
        );
    }

    /**
     * 商家端 专题详情校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function merchantDetailValidate(array $params)
    {
        return self::getInstance()->validate(
            ["id", "pageSize", "pageNum"],
            $params,
            [
                "id"       => [
                    "required",
                    "int",
                    Rule::exists((new ArticleCategoryModel())->getTable(), "id")
                        ->where("isDeleted", BaseModel::DELETE_NO)
                ],
                "pageSize" => "required|int|min:1|max:100",
                "pageNum"  => "required|int|min:1",
            ]
        );
    }
}
